#ifndef UTIL_H_
#define UTIL_H_

#include<functional>

class Timer{
public:
    Timer()=default;
    ~Timer()=default;

    void restart()
    {
        delta_time=0;
        is_shooted=false;
    }

    void set_one_shoot(bool flag)
    {
        is_one_shoot=flag;
    }

    void set_wait_time(int time)
    {
        wait_time=time;
    }

    void set_callback(std::function<void()> callback)
    {
        this->callback=callback;
    }

    void on_update(int delta)
    {
        delta_time+=delta;

        if(delta_time>wait_time)
        {
            if((!is_shooted || !is_one_shoot) && callback)
            callback();

            delta_time-=wait_time;
            is_shooted=true;
        }
    }

private:
    bool is_shooted=false;
    bool is_one_shoot=true;
    int wait_time;
    int delta_time;
    std::function<void()> callback;
};

#endif